function getSelectionText() {
    var win = window,
        doc = document;

    if (win.getSelection) {
        var range = win.getSelection().getRangeAt(0);
        var container = win.document.createElement('div');
        container.appendChild(range.cloneContents());
        return container.innerText || container.innerHTML.replace(/<[^>]+>/g,'');
    } else if (doc.getSelection) {
        var range = doc.getSelection().getRangeAt(0);
        var container = win.document.createElement('div');
        container.appendChild(range.cloneContents());
        return container.innerText || container.innerHTML.replace(/<[^>]+>/g,'');
    } else if (doc.selection) {
        // return win.document.selection.createRange().htmlText; // for ie
        return doc.selection.createRange().text; // for ie
    }
}
